package com.lagou.service.impl;


import com.lagou.service.WebServerFactory;
import org.apache.catalina.startup.Tomcat;
import org.springframework.stereotype.Component;

@Component
public class MyTomcat implements WebServerFactory {
    public void createServer() throws Exception {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8081);
        tomcat.addWebapp("/", "/Library/Java/apache-tomcat-9.0.30/webapps");
        tomcat.start();
        //因为  tomcat.start();是非阻塞型的，所以要阻塞一下，不能让服务停止。
        tomcat.getServer().await();
    }
}
